﻿using Client.ServerServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Client
{
    /// <summary>
    /// Interaction logic for Registration.xaml
    /// </summary>
    public partial class Registration : UserControl
    {
        private MainWindow mainWindow;

        public Registration()
        {
            InitializeComponent();
        }

        public Registration(MainWindow mainWindow)
        {
            InitializeComponent();
            this.mainWindow = mainWindow;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ServerServices.RegistrationRequest regReq = new ServerServices.RegistrationRequest();
            regReq.Username = usernameRegTextbox.Text;
            regReq.Password = passwordRegBox.Password;
            regReq.EmailAddress = emailTextbox.Text;
            ServerServices.RegistrationServiceResponse response;

            try
            {
                response = mainWindow.client.RegistrationProcess(regReq);
                if (response.Code == 100)
                {
                    if (MessageBox.Show("Sikeres regisztráció") == MessageBoxResult.OK)
                    {
                        mainWindow.SetScreen("login");

                    }
                }
                else
                {
                    MessageBox.Show("Sikertelen regisztráció. Hibakód: " + response.Code + " " +response.Message);
                }

            }
            catch (Exception)
            {
                MessageBox.Show("Sikertelen regisztráció. szerverhiba");
                mainWindow.client.Abort();
                mainWindow.GoToServer();
            }
            
        }

        private void BackToLoginButton_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.SetScreen("login");
        }
    }
}
